SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Get form value with javascript

    Hi,

    I have a form with two fields, Item_Price and Item_Name

    Item_Price looks like this:

    <select name="Item_Price">
    <option value="19.95">24" x 36" - Photo Glossy Paper</option>
    <option value="24.95">24" x 36" - Satin Finish Paper</option>
    </select>

    Item_Name needs some javascript to do this:

    <input type=hidden name="Item_Name" value="get the value of Item_Price option (not option value)">

    Thanks in advance
    Last edited by ee-o; Sep 25, 2001 at 03:19.

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does anyone know how to do this

  3. #3
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i have an idea for how to do this. i will try to post a solution in a couple of hours as I am currently at work.

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Makeda,
    Ill be waiting for you.

  5. #5
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is something that will work..at least with IE. The function is attatched to the onChange event for the dropdown menu. I didn't write any onload events or anything so this thing will start working once you change the dropdown menu for the first time. You can easilly modify it to your liking:

    <html>
    <head>
    <script language="javascript">
    function writeHiddenValue(refDropDown) {
    sOtherVal = frmElForm.Item_Price[refDropDown.selectedIndex].otherVal;
    frmElForm.Item_Name.value = sOtherVal;
    }

    function testFunction() {
    alert(frmElForm.Item_Name.value)
    }

    </script>

    </head>
    <body>
    <form name="frmElForm" method="" action="">
    <select name="Item_Price" onChange="writeHiddenValue(this);">
    <option value="19.95" otherVal="24 x 36 - Photo Glossy Paper">24" x 36" - Photo Glossy Paper</option>
    <option value="24.95" otherVal="24 x 36 - Satin Finish Paper">24" x 36" - Satin Finish Paper</option>
    </select>
    <input type=hidden name="Item_Name" value="">
    <p />
    <div align="center"><input type="button" value="Click Here To View Hidden Value" onClick="testFunction();"></div>
    </form>
    </body>
    </html>

  6. #6
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    one other thing, i noticed that you had some quotes in your values. I don't know what you're doing but one possible work around is using &quot;. It works in the alert boxes or you could write a little regEx to put them in:

    <option value="19.95" otherVal="24&quot; x 36 - Photo Glossy Paper">24" x 36" - Photo Glossy Paper</option>

    <option value="24.95" otherVal="24&quot; x 36 - Satin Finish Paper">24" x 36" - Satin Finish Paper</option>

    update: this bulletin board is rendering my HTML encoded quotation marks. my work around is to put the HTML encoded version of " next to your numbers. follow?
    Last edited by makeda; Sep 26, 2001 at 09:55.

  7. #7
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Makeda,
    I sent you a private message,

    Thanks

  8. #8
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i replied to your pm.


Bookmarks

Posting Permissions

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