Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    New Coder
    Join Date
    Jul 2004
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Value to a hidden field

    Does anyone know how to pass a value from the marquee tag to a hidden field?
    i.e
    Code:
    <?php
    $message_content="wibble"
    ?>
    
    <body>
    
    
    <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>
    
    <input name="HiddenMessage" type="hidden" id="HiddenMessage" 
    value="<?php echo $_GET['$message_content']; ?>" />
    <input type="hidden" name="MM_insert" value="scroll_frm">
        </form>
    </body>
    Last edited by antler; 08-10-2004 at 12:24 PM.

  • #2
    Regular Coder
    Join Date
    Dec 2003
    Location
    America
    Posts
    544
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Could you elaborate a little? I mean, do you want to have a button that passes the value from one field, to another? Or do you want it with in the same function?

    Logic dictates that if you create a path to a specific form element, that you must also create a path to another form element.

    Code:
    function message(){
    
      var hidEle=document.form['whatever name']['whatever name'];
    
      var obj=document.getElementById("wibble");
      var message=prompt("Please type a message (200 character max)","");
    
      obj.innerHTML=message;
      hidEle.value=message;                     
    }
    I would presume thats how it works.
    LovesWar

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,047
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Quote Originally Posted by SpiritualStorms
    Could you elaborate a little? I mean, do you want to have a button that passes the value from one field, to another? Or do you want it with in the same function?

    Logic dictates that if you create a path to a specific form element, that you must also create a path to another form element.

    Code:
    function message(){
    
      var hidEle=document.form['whatever name']['whatever name'];
    
      var obj=document.getElementById("wibble");
      var message=prompt("Please type a message (200 character max)","");
    
      obj.innerHTML=message;
      hidEle.value=message;                     
    }
    I would presume thats how it works.
    Should have the s in form

    var hidEle=document.forms['whatever name']['whatever name'];

  • #4
    New Coder
    Join Date
    Jul 2004
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by SpiritualStorms
    Could you elaborate a little? I mean, do you want to have a button that passes the value from one field, to another? Or do you want it with in the same function?

    Logic dictates that if you create a path to a specific form element, that you must also create a path to another form element.

    Code:
    function message(){
    
      var hidEle=document.form['whatever name']['whatever name'];
    
      var obj=document.getElementById("wibble");
      var message=prompt("Please type a message (200 character max)","");
    
      obj.innerHTML=message;
      hidEle.value=message;                     
    }
    I would presume thats how it works.
    Ok, What I had in mind was related to the whole message and formatting thing from earlier posts.

    A user writes a message (via the function above "message()") but how could that text be saved to a database when the user clicks a button called submit?

    I thought about putting a hidden field into the form named for example, HiddenMessage, and then somehow directing the text written via the message() function to that hidden field.

    In theory I could then insert the contents of the hidden field "Hidden Message" into the database like this:
    Code:
    f ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "text_frm")) {
      $insertSQL = sprintf("INSERT INTO Text (Message) VALUES (%s,
                           GetSQLValueString($_POST['HiddenMessage'], "text"),
    The problem is that I do not know how to specify the path from message() to HiddenMessage.

    I will take a look at the examples you have posted.

    any further points in the right direction appreciated!

    antler.

  • #5
    New Coder
    Join Date
    Jul 2004
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    function message()
    
    var hidEle=document.form['HiddenMessage']['hiddenMessage'];
    
    hidEle.value=message;
    So, is this saying that into the local variable "hidEle" goes the "document" object and the property "form" ['the_document']['HiddenMessage'];

    Is that a path to the hidden field in the form "HiddenMessage", so when the user starts the message() function the value of hidEle is sent to HiddenMessage?

  • #6
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    625
    Thanks
    0
    Thanked 0 Times in 0 Posts
    var message=prompt("Please type a message (200 character max)","");

    You are invoking the function from your form, right? If so, the value of message is already set to whatever is typed into the prompt. You don't need a hidden field. Just grab the value in php as $message when it is passed via the form submission.


    -james
    Last edited by jamescover; 08-11-2004 at 03:01 PM.
    "God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "

  • #7
    Regular Coder
    Join Date
    Dec 2003
    Location
    America
    Posts
    544
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Dude. You use variables to to store data. If the goal is to pass data from one location, to another, then you will use a variable. When you create a path, all you are doing is giving the variable a direction to go to for the collection of data. Thus, you use the dot syntax as a means of passing data to a variable:

    Code:
    var hidEle=document.form['whatever name']['whatever name'];
    With the above, you have basically created a representation. Your variable will now represent an object. The object of course is a form element. First part, is simply connecting to the document object since obviously thats where you form element will be. Now because your document can contain many things, like an image, links, text, and the what not, the next step is to specify the form object. Now, since the form object can contain more than one form element, you will need to specify which of those form elements you are interested in, hence, the second part in the brackets.

    Now, if you have a variable that represents a form element, and you want to assign, or store a value in the value property of that form element, then you will do something like this:

    Code:
    var hidEle=document.form['whatever name']['whatever name'];
    
    hidEle.value=message;
    If we assume that your hidEle actually represents a specific form element, then you can now access any of that form elements properties:

    Code:
    var hidEle=document.form['whatever name']['whatever name'];
    
    hidEle.value;
    hidEle.name;
    hidEle.type;
    And so on, and on.

    Since you goal is to store something inside a hidden field, it would make sense to think then that you would ultimately do something like this:

    Code:
    function message(){
    
      var hidEle=document.form['whatever name']['whatever name'];
    
      var obj=document.getElementById("wibble");
      var message=prompt("Please type a message (200 character max)","");
    
      obj.innerHTML=message;
    
      hidEle.value=message;       
    }
    By having a variable, you can cut down on the number of times you have to basically create a path to the very property you are interested in. Since you want store data in a hidden field, you will need to do this:

    Code:
    hidEle.value=message;
    If we assume that message is a variable, and hidEle is another variable, then we will use one variable to access the value property, and then assign to that property the contents of another variable, such a variable by the name of message.

    I thought i went through this with you? I thought i specifically said something about the accessing of a particular property of a particular tag? Why arent you getting this part?

    In the above, hidEle is the variable, and the value property is representefed by, hidEle.value. Since we want to store something inside it, we use the assignement operator, thus its hidEle.value=. Once, we have the assignment operator, then its a matter of knowing what will assign. Since you want what is typed in a prompt() method, we will basically attach a variable at the end of the assignment operator, bring our previous to this final statement:

    hidEle.value=message.

    Whatever is stored in message, will now be relocated to the hidden field property that is responsible for the holding of data, which is generally the value property.
    Last edited by SpiritualStorms; 08-11-2004 at 04:08 PM.
    LovesWar

  • #8
    New Coder
    Join Date
    Jul 2004
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It didn't work for me.

    What I do not understand is what goes in ['whatever name']['whatever name'] obviously.

    The name of what? the value of what? The id of what?

    That is what I did not understand.
    Last edited by antler; 08-11-2004 at 03:52 PM.

  • #9
    Regular Coder
    Join Date
    Dec 2003
    Location
    America
    Posts
    544
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Did i not say that when you create a form tag, that you could give it a name? Did i not also say that you can give a form element a name?

    Code:
    <form name="forest">
    
    <input type="hidden" name="tree">
    
    </form>
    Well, if i have something like that, i think i would probably do something like,

    Code:
    var hidEle=document.forms['forest']['tree'];
    Any questions?
    LovesWar

  • #10
    New Coder
    Join Date
    Jul 2004
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah, I was kind of afraid you would say that:

    Code:
     function message(){
    var hidEle=document.form['scroll_frm']['HiddenMessage'];
    			
    var obj=document.getElementById("wibble");
    var message=prompt("Please type a message (200 character max)","");
              
                
    obj.innerHTML=message;
    hidEle.value=message; 
                         }
    My form is called scroll_frm and the hidden field is called HiddenMessage.

    I just get error on page.

  • #11
    Regular Coder
    Join Date
    Dec 2003
    Location
    America
    Posts
    544
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What is the nature of your error? You will need to provide details if one is to know what exactly seems to be the problem.
    LovesWar

  • #12
    New Coder
    Join Date
    Jul 2004
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Error on page is displayed in left hand corner of the status bar when I click the button to initiate message().

    Code:
    <BODY>
    
    <form action="<?php echo $editFormAction; ?>
    " name="scroll_frm" id="scroll_frm" method="POST">
          <table width="280" border="1" bordercolor="#996666">
            <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 hidEle=document.form['scroll_frm']['HiddenMessage'];
    			
                var obj=document.getElementById("wibble");
                var message=prompt("Please type a message (200 character max)","");
              
                
    			obj.innerHTML=message;
    			hidEle.value=message; 
                         } 
                </script>
             
    <input name="write " type="button" id="write " 
              onClick="message(); " value="Clcik to type text">
    <input name="HiddenMessage" type="hidden" id="HiddenMessage" />
        <input type="hidden" name="MM_insert" value="scroll_frm">
        </form>

  • #13
    Regular Coder
    Join Date
    Dec 2003
    Location
    America
    Posts
    544
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Did you click on the yellow triangle by the status bar? Generally, if you click on it, it will pop up a debugger screen. In the debugger screen, it will tell you the line at which the code is erroring, and the generally the charactor position at which it errors. What does it say?
    LovesWar

  • #14
    New Coder
    Join Date
    Jul 2004
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts
    'document.form.scroll_frm' is null or not an object.

  • #15
    Regular Coder
    Join Date
    Jun 2004
    Posts
    565
    Thanks
    0
    Thanked 18 Times in 18 Posts
    As stated in the 3rd post:

    var hidEle=document.forms['scroll_frm']['HiddenMessage'];

    dumpfi


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •