SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Xbox why have you forsaken me? moospot's Avatar
    Join Date
    Feb 2001
    Location
    Clearwater, FL
    Posts
    3,615
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple Function Help

    I have a link that I want to click and show the correct option in a drop down list. This part is easy. What is mystifying me is that the value I am passing has a dash (-) in it and it doesn't seem to work. If I take the dash out, it works fine.

    Anyway, onto the JS code
    Code:
    function SelectFF(skunum) {
    var presku = "30-A-";
     if (prod_form.sku.tagName != skunum){   
       tmpsku = presku + skunum;
       alert(tmpsku);
       prod_form.sku.selectedIndex = tmpsku;
     } 
    }
    The HTML

    Code:
    <a href="#" onClick="SelectFF('04');"><img href="/store/Assets/product_images/thumbs/30/A-04.JPG"></a>
     
    <select name="sku" size="1">
    	  <option value="none">Select a Style</option>
    	  <optgroup label="Flip Styles"> 
    	  <option value="30-A-04">Floppy Flip</option>
    </select>
    If I change <option value="30-A-04"> to <option value="04">, it works fine. But I need the dash, because its the sku number. I tried adding it in the JS code, but that doesnt seem to work either. No errors. If I use an alert box, it will display the correct value. It just doesnt pass it back to the page and change the drop down.

    Any ideas?

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need something different
    Code:
    function setSel( f, selName, val )
    {
    	var i, opt, selObj = f.elements[selName];
     
    	for ( i = 0; ( opt = selObj.options[i] ); i++ )
    		if ( opt.value == val )
    		{
    			selObj.selectedIndex = i;
    			break;
    		}
    }
    then...
    Code:
    <a href="#" onClick="setSel(document.prod_form, 'sku','30-A-04');"><
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    Xbox why have you forsaken me? moospot's Avatar
    Join Date
    Feb 2001
    Location
    Clearwater, FL
    Posts
    3,615
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Beetle, you've done it again! Muchas Gracias

  4. #4
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm here 24-7 to handle all your JS needs!

    Actually, I just cut'n'pasted that from my own function collection
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev





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
  •