+ Reply to Thread
Results 1 to 10 of 10

Thread: Javascript Help

  1. #1
    garycocs's Avatar
    garycocs is offline Wannabe Geek garycocs will become famous soon enough
    Join Date
    Oct 2007
    Location
    Dubland
    Posts
    326
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Javascript Help

    Lads again my JS knowledge is letting me down in AJAX.

    My ajax is returning the code

    Code:
    addPubNum( 5940, '1796 Wolfe Tone Bar' , 'pubid1' );
    
    This function can be seen here:

    Code:
    function addPubNum( id, name, pubnum ) {document.forms['addpub'].elements[ pubnum ][ document.forms['addpub'].elements[ pubnum].length ] = new Option( name, id );}
    
    The problem is that this function/code isn't populating the form:

    Code:
    <table width="100%">    <form name="addpub" action="userpage.php" method="GET">
                                                                    
        <tr><td colspan="2">Please Enter Your 1st Pub</td></tr>
        <tr><td><select name="countyid" onChange="showPubNum(1,this.value);"><option value="0">Select County</option>
        <option value="1">Antrim</option>
        <option value="2">Armagh</option>
        </select></td>        
        <td><select name="pubid1"><option value=""></option></select> </td></tr>
        <tr><td colspan="2" align="right"><input type="submit" value="Add"></td></tr>
    </form></table>
    

    If anyone could see an error off the top of their head that would be great!

    P.S. -> showPubNum(1,this.value); is working fine!

  2. #2
    louie's Avatar
    louie is offline Senior Member louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough
    Join Date
    Jan 2006
    Location
    Dublin, Ireland
    Posts
    2,328
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    where is this element on your form?

    pubnum
    :. Web Design & Development Web Design Ireland
    :. Search Engines Optimization Search Engines Optimization
    :. Car Parts & Accessories Car Parts
    :. Cars Ireland Cars Ireland
    :. I Have 2 Find It Directory SEF Directory

  3. #3
    garycocs's Avatar
    garycocs is offline Wannabe Geek garycocs will become famous soon enough
    Join Date
    Oct 2007
    Location
    Dubland
    Posts
    326
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by louie View Post
    where is this element on your form?

    pubnum
    I am using pubnum as a variable (Sorry about my naming schemes it was late last night doing this one)

    basically I want to take a variable into the function to select which element to change.

    in this case I want to change pubid1 so I take in variable pubid1.

  4. #4
    louie's Avatar
    louie is offline Senior Member louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough
    Join Date
    Jan 2006
    Location
    Dublin, Ireland
    Posts
    2,328
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    I need more info and code...
    :. Web Design & Development Web Design Ireland
    :. Search Engines Optimization Search Engines Optimization
    :. Car Parts & Accessories Car Parts
    :. Cars Ireland Cars Ireland
    :. I Have 2 Find It Directory SEF Directory

  5. #5
    garycocs's Avatar
    garycocs is offline Wannabe Geek garycocs will become famous soon enough
    Join Date
    Oct 2007
    Location
    Dubland
    Posts
    326
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Sorry Louie and thanks for your time

    The page can be found here: Find and Rate Pubs in Ireland the ajax is ran when you select a county.

  6. #6
    garycocs's Avatar
    garycocs is offline Wannabe Geek garycocs will become famous soon enough
    Join Date
    Oct 2007
    Location
    Dubland
    Posts
    326
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Got it sorted Louie. Nice one!

  7. #7
    louie's Avatar
    louie is offline Senior Member louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough
    Join Date
    Jan 2006
    Location
    Dublin, Ireland
    Posts
    2,328
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    garry you are all over the place with that AJAX code.

    What are you trying to do? Push options into the select menu or replace the select menu with a new one?
    :. Web Design & Development Web Design Ireland
    :. Search Engines Optimization Search Engines Optimization
    :. Car Parts & Accessories Car Parts
    :. Cars Ireland Cars Ireland
    :. I Have 2 Find It Directory SEF Directory

  8. #8
    garycocs's Avatar
    garycocs is offline Wannabe Geek garycocs will become famous soon enough
    Join Date
    Oct 2007
    Location
    Dubland
    Posts
    326
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    How do you mean all over the place?

    I run the ajax on a select, this pushes to the ajax.php which returns a set of javascript commands which I run to populate the options?

  9. #9
    louie's Avatar
    louie is offline Senior Member louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough
    Join Date
    Jan 2006
    Location
    Dublin, Ireland
    Posts
    2,328
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    try this solution:
    PHP Code:
    <script type="text/javascript">
    var 
    xmlHttp;
    function 
    addPubNumidnamepubnum ) {
     
    document.forms['addpub'].elementspubnum ][ document.forms['addpub'].elementspubnum].length ] = new Optionnameid )
    }
    function 
    remPubNumpubnum ) {
     while( 
    document.forms['addpub'].elementspubnum ].length document.forms['addpub'].elementspubnum ][0] = null
    }

    function 
    showPubNum(pubnum,countyid){ 
     
    xmlHttp=GetXmlHttpObject();
     if (
    xmlHttp==null) {
       
    alert ("Browser does not support HTTP Request");
       return;
      }
     var 
    span_select document.getElementById("pubnum");
     var 
    url="ajax.php?";
     
    //url=url+"?pubnum="+pubnum
     
    url=url+"countyid="+countyid;
     
    url=url+"&sid="+Math.random();
     
    xmlHttp.onreadystatechange=stateChangedPubNum('span_select');
     
    xmlHttp.open("GET",url,true);
     
    xmlHttp.send(null);
    }
    function 
    stateChangedPubNum('span_select') { 
     if (
    xmlHttp.readyState==|| xmlHttp.readyState=="complete") { 
       
    //eval( xmlHttp.responseText  );
       
    document.getElementById("span_select").innerHTMLxmlHttp.responseText ;
      } 
    }

    function 
    GetXmlHttpObject(){
     var 
    xmlHttp=null;
     try
      {
      
    // Firefox, Opera 8.0+, Safari
      
    xmlHttp=new XMLHttpRequest();
      }
     catch (
    e)
      {
      
    //Internet Explorer
      
    try
       {
       
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
       }
      catch (
    e)
       {
       
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
       }
      }
     return 
    xmlHttp;
    }
    </script>
    </head>
    <body>
     <select name="countyid" onChange="showPubNum('span_pubid1',this.value);">
         <option value="">Select County</option>
            <option value="1">Antrim</option>
            <option value="2">Armagh</option>
            <option value="3">Carlow</option>
            <option value="4">Cavan</option>
            <option value="5">Clare</option>
            <option value="6">Cork</option>
            <option value="7">Derry</option>
            <option value="8">Donegal</option>
            <option value="9">Down</option>
            <option value="10">Dublin</option>
            <option value="11">Fermanagh</option>
            <option value="12">Galway</option>
            <option value="13">Kerry</option>
            <option value="14">Kildare</option>
            <option value="15">Kilkenny</option>
            <option value="16">Laois</option>
            <option value="17">Leitrim</option>
            <option value="18">Limerick</option>
            <option value="19">Longford</option>
            <option value="20">Louth</option>
            <option value="21">Mayo</option>
            <option value="22">Meath</option>
            <option value="23">Monaghan</option>
            <option value="24">Offaly</option>
            <option value="25">Roscommon</option>
            <option value="26">Sligo</option>
            <option value="27">Tipperary</option>
            <option value="28">Tyrone</option>
            <option value="29">Waterford</option>
            <option value="30">Westmeath</option>
            <option value="31">Wexford</option>
            <option value="32">Wicklow</option>
        </select> 
     <span id="span_pubid1"><select name="pubid1" disabled="disabled"><option value=""></option></select></span>
     <input type="submit" value="Add"> 
    :. Web Design & Development Web Design Ireland
    :. Search Engines Optimization Search Engines Optimization
    :. Car Parts & Accessories Car Parts
    :. Cars Ireland Cars Ireland
    :. I Have 2 Find It Directory SEF Directory

  10. #10
    louie's Avatar
    louie is offline Senior Member louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough
    Join Date
    Jan 2006
    Location
    Dublin, Ireland
    Posts
    2,328
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    You got it.. cool
    :. Web Design & Development Web Design Ireland
    :. Search Engines Optimization Search Engines Optimization
    :. Car Parts & Accessories Car Parts
    :. Cars Ireland Cars Ireland
    :. I Have 2 Find It Directory SEF Directory

+ Reply to Thread

Similar Threads

  1. Javascript loop
    By louie in forum Coding Help
    Replies: 13
    Last Post: 01-02-2008, 09:27 PM
  2. Javascript problem
    By ph3n0m in forum Coding Help
    Replies: 1
    Last Post: 21-06-2007, 03:57 PM
  3. javascript
    By 7aken in forum Coding Help
    Replies: 1
    Last Post: 03-04-2007, 03:50 PM
  4. javascript help
    By 7aken in forum Coding Help
    Replies: 2
    Last Post: 20-02-2007, 06:09 AM
  5. Javascript/CSS menu help?
    By ButtermilkJack in forum Coding Help
    Replies: 4
    Last Post: 16-04-2006, 05:59 PM

Visitors found this page by searching for:

Nobody landed on this page from a search engine, yet!
SEO Blog

Tags for this Thread

Posting Permissions

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

Search Engine Optimization by vBSEO

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64