SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict itsource's Avatar
    Join Date
    Jun 2001
    Location
    Thailand
    Posts
    369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    get value and something from form using JavaScript

    I have text box, list box and submit button
    PHP Code:
    <form name=myform>
    <
    input type=text name=myname>
    <
    select name=myname2>
    <
    option value="1">Number one</option>
    <
    option value="2">Number two</option>
    <
    option value="3">Number three</option>

    <
    input type=submit onclick="return confirm('are you ok?')">
    </
    form
    If I type "Pentium" in text box
    and select Number two in list box

    I have to variable myname=Pentium and myname2=2(not Number two)

    I want to when click submit, java Script popup dialog and ask "are you OK to type Pentium and choose Number two"

    How can I write in javascript?
    I live in Thailand. My English grammar not well.

  2. #2
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,123
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <html>
    <head>
    <title>
    	La DI Da
    </title>
    <script language="javascript">
    <!--
    
    function doCheck(loc,num)
    {
    	window.alert('Are you sure you want to select ' + loc + ' and ' + num + '?');
    }
    
    // -->
    </script>
    
    </head>
    
    <body>
    
    <form name="myform">
    <input type="text" name="myname">
    <select name="myname2">
    	<option value="1">Number one</option>
    	<option value="2">Number two</option>
    	<option value="3">Number three</option>
    </select>
    
    <input type="submit" onclick="doCheck(this.form.myname,this.form.myname2);">
    </form>
    
    </body>
    </html>
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  3. #3
    SitePoint Addict itsource's Avatar
    Join Date
    Jun 2001
    Location
    Thailand
    Posts
    369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Jeremy W.
    but dialog has print

    Are you sure you want to select [object] and [object]
    I live in Thailand. My English grammar not well.

  4. #4
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,123
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Sorry, it should be:

    <input type="submit" onclick="doCheck(this.form.myname.value,this.form.myname2.value);">
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  5. #5
    SitePoint Addict itsource's Avatar
    Join Date
    Jun 2001
    Location
    Thailand
    Posts
    369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <input type="submit" onclick="doCheck(this.form.myname.value,this.form.myname2.value);">

    PHP Code:
    <select name="myname2">
        <
    option value="1">Number one</option>
        <
    option value="2">Number two</option>
        <
    option value="3">Number three</option>
    </
    select


    As I first post, if I select option2 so "this.form.myname2.value" print "2" but I want it print "Number two" not "2" value. Please help me again?
    I live in Thailand. My English grammar not well.

  6. #6
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,123
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Then change the value to "two" instead...
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright


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
  •