Board index   FAQ   Search  
Register  Login
Board index php forum :: HTML JavaScript

Pass a variable value to a hidden field

Javascript coding ..

Moderators: macek, egami, gesf

Pass a variable value to a hidden field

Postby trufla » Mon Aug 09, 2004 4:56 am

I have been drinking lots of coke :grin: to get me through this but I am just sugar rushing now and not thinking!

Scenario:

I have a a form containing 3 drop down boxes: BgColour, TextColour, Font.

A user clicks a button called "write message" (in the same form) and a Javascript prompt pops up. The user types a message into the prompt and clicks ok.

The message the user typed into the prompt is then scrolled along the screen by way of the <marquee> tag.

The user can format the text using the drop down boxes I described earlier.

The user, once the message is written and formatting is chosen, can click another button "submit" and save their changes to a database.

Problem:

The selection of the formatting is saved. But, I do not know how to save the message. I am not sure if this is a Javascript problem or a php matter.
I have given the marquee tag and id called "wibble", I thought about using "wibble" and attaching it to a hidden field within the form but I do not know how to do this.

Here is the code:
Code: Select all
<?php require_once('../Connections/gymtvdb.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;   
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "scroll_frm")) {
  $insertSQL = sprintf("INSERT INTO scrolls (Gym, Location, Message, Font, FontColour, Background) VALUES (%s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['GymName'], "text"),
                       GetSQLValueString($_POST['GymLoc'], "text"),
                       GetSQLValueString($_POST['HiddenMessage'], "text"),
                       GetSQLValueString($_POST['theChoices'], "text"),
                       GetSQLValueString($_POST['d2'], "text"),
                       GetSQLValueString($_POST['c2'], "text"));

  mysql_select_db($database_gymtvdb, $gymtvdb);
  $Result1 = mysql_query($insertSQL, $gymtvdb) or die(mysql_error());

  $insertGoTo = "thankyou.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Insert into Database test</title>

<script language="javascript1.2">


     function changeBgColor( obj){
     
    var property1=document.getElementById("wibble").style;
         if( obj ){
         theLink = obj.selectedIndex;
         property1.backgroundColor=obj.options[theLink].value;
              }
           }

     function changeFontColor( obj){

     var property1=document.getElementById("wibble").style;
        if( obj ){
      theLink = obj.selectedIndex;
        property1.color = obj.options[theLink].value;
              }
          }
       
     function changeFont( obj ) {

       var property1 = document.getElementById("wibble").style;
          if( obj ){
          var theLink = obj.selectedIndex;
          property1.fontFamily =  obj.options[theLink].value;
               }
           }
</script>

<link href="../css/gymtv.css" rel="stylesheet" type="text/css" />
</head>

<body>

<table width="280" border="0" bordercolor="#996666">
  <tr>
    <td colspan="2" bordercolor="#FFFFFF"><form name="scroll_frm" id="scroll_frm" method="POST" action="<?php echo $editFormAction; ?>">
      <table width="280" border="1" bordercolor="#FFFFFF">
        <tr bordercolor="#FFFFFF">
          <td height="60" colspan="2">
       
        <marquee behavior=scroll direction="left"
            bgcolor="white" id="wibble"  style="font-size:28px">
            </marquee>
           
         <div align="left">

            <script language="JavaScript" type="text/javascript">
 
            function message(){

            var obj=document.getElementById("wibble");
            var message=prompt("Please type a message (200 character max)","");

            obj.innerHTML=message;
                     }
            </script>
         
      
       </td>
          </tr>
        <tr bordercolor="#996666">
          <td width="152"><select name = "c2" size = "1">
        <?php
          $colours = array('blue','red','Lightblue'
                 ,'antique white','Brown', 'Crimson', 'Darkkhakki', 'Darkorange'  );
          foreach($one as $colours)
          {
          if($one == $c2) $selected = ' SELECTED';
          echo "<option value=\"$one\"$selected>$one</option>\n";
          $selected = '';
          }
          ?>

       
         <option value="blue" selected="selected">Blue</option>
        <option value ="red" >' red </option>
        <option value ="Lightblue"> lightblue </option>
        <option value ="Antiquewhite"> antique white </option>
        <option value ="Brown"> brown </option>
        <option value ="Crimson"> crimson </option>
        <option value ="Darkkhaki"> khaki green </option>
        <option value ="Darkorange"> dark orange </option>
                                                          </select></td>
          <td width="118"> <input name="BgColor" type="button" id="BgColor"
                           onClick="changeBgColor(document.scroll_frm.c2);"
                     value="BgColor"  ></td>
        </tr>
        <tr bordercolor="#996666">
          <td><select name = "d2" size = "1">
            <option value="blue" selected="selected">Blue</option>
        <option value ="Navy"> Navy </option>
        <option value ="orange"> orange </option>
        <option value ="Antiquewhite"> antique white </option>
        <option value ="Brown"> brown </option>
        <option value ="white"> white </option>
        <option value ="Crimson"> crimson </option>
        <option value ="Darkkhaki"> khaki green </option>
        <option value ="Darkorange"> dark orange</option>
              </select></td>
          <td><input name="textColor" type="button" id="textColor"
onclick="changeFontColor( document.scroll_frm.d2 );" value="textColor" /></td>
        </tr>
        <tr bordercolor="#996666">
          <td><select name = "theChoices" size = "1" >
            <option value="Times New Roman" selected="selected">Times</option>

     <option value ="Arial">  Arial  </option>

     <option value ="Verdana">  Verdana </option>
     <option value="Comic Sans MS">Comic Sans</option>

                    </select></td>
          <td><input name="fontType" type="button" id="fontType"
        onClick="changeFont(document.scroll_frm.theChoices );"  value="fontType"></td>
        </tr>
        <tr bordercolor="#FFFFFF">
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr bordercolor="#FFFFFF">
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr bordercolor="#FFFFFF">
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td bordercolor="#FFFFFF">&nbsp;</td>
          <td bordercolor="#996666"><input type="button" value="Write Message"
          onClick="message(); ">
</td>
        </tr>
      </table>
      <table width="280" border="0">
        <tr>
          <td colspan="2"><p>&nbsp;</p>
            <p>Once you are happy with the message, fill in the form
              below and click submit. </p>
            <p>&nbsp;</p></td>
          </tr>
        <tr>
          <td width="129">Gym</td>
          <td width="141"><input name="GymName" type="text" id="GymName" /></td>
        </tr>
        <tr>
          <td width="129">Location</td>
          <td><input name="GymLoc" type="text" id="GymLoc" /></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><input name="SubmitScrolls" type="submit" id="SubmitScrolls" value="Submit" /></td>
        </tr>
      </table>
      <p>&nbsp;</p>
      <input type="hidden" name="MM_insert" value="scroll_frm">
      <input name="HiddenMessage" type="hidden" id="HiddenMessage" />
    </form></td>
  </tr>

</table>
</body>
</html>



I am a newbie so don't be afraid to make your posts idiot proof!
User avatar
trufla
New php-forum User
New php-forum User
 
Posts: 30
Joined: Wed Jul 21, 2004 5:21 am
Location: North West, UK

Postby trufla » Mon Aug 09, 2004 6:17 am

Anyone?
User avatar
trufla
New php-forum User
New php-forum User
 
Posts: 30
Joined: Wed Jul 21, 2004 5:21 am
Location: North West, UK

Postby Redcircle » Mon Aug 09, 2004 3:00 pm

hidden input tags are handled just like any other input tags. $_POST['HiddenMessage']
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

Postby ruturajv » Sun Aug 15, 2004 7:27 pm

You can add the values as this
Code: Select all
<script type="text/javascript">
d = document.getElementById("wiggle")
value =d.innerHTML;

document.forms[0].elements['hidden_value'] = value;
...

submit the form..
</script>
User avatar
ruturajv
php-forum Super User
php-forum Super User
 
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India


Return to JavaScript

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron