SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    2 different values from 1 selectbox?

    I'm trying to send data to 2 different functions using the same selectbox. 1 function only needs a "ID" as value like this:
    Code HTML4Strict:
    <select name="ccountry" onchange="getState(this.value)">
    	<option value="1">USA</option>
        <option value="2">England</option>
    </select>

    The other one needs an url like this:
    Code HTML4Strict:
    <select id="ajaxmenu" onChange="ajaxcombo('ajaxmenu', 'contentarea')">
    	<option value="ajax.php?page=country&amp;code=1">USA</option>
        <option value="ajax.php?page=country&amp;code=1">England</option>
    </select>

    I have an idea, but not sure how to do it... If I use the last example and then somehow in my javascript function would be able to, like in php, extract the code=1 so I would get only the "1"...

    Is there any way to do so?

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Yes, you would have to do some simple string manipulation within your ajaxcombo function. The way you have it set up at the moment, your ajaxcombo is just receiving two static strings. You also need it to receive this.value like your first function (so a third argument). Then extract the code number from the string, using a regular expression or one of the string functions.

  3. #3
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, trying to leave the ajaxcombo as is, but trying to extract the "code=1" part from the string like this:
    Code JavaScript:
    var URL = "ajax.php?page=country&amp;code=1";
    var d = URL.lastIndexOf("code");
    var newURL = URL.substring(d);
    alert (newURL);

    But... Gives me to problems:
    The alert comes out like this: "code=1", and all I want is the "1", and what if I have a urlstring like this:
    Code JavaScript:
    var URL = "ajax.php?page=country&amp;code=1&id=15";

    and I only want the "code" value...

    Any ideas?


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
  •