Irish SEO,  Marketing & Webmaster Discussion

 

Javascript Help

This is a discussion on Javascript Help within the Coding Help forums, part of the Webmaster Help category; Lads again my JS knowledge is letting me down in AJAX. My ajax is returning the code Code: addPubNum( 5940, ...


Go Back   Irish SEO, Marketing & Webmaster Discussion > Webmaster Help > Coding Help

Register Forum Rules FAQDonate Members List Calendar Search Today's Posts Mark Forums Read


Notices

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 30-07-2008, 11:00 AM
garycocs's Avatar
Wannabe Geek
Recent Blog: Bangkok
 
Join Date: Oct 2007
Location: Dubland
Posts: 154
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
garycocs will become famous soon enough
Send a message via AIM to garycocs Send a message via MSN to garycocs Send a message via Yahoo to garycocs Send a message via Skype™ to garycocs
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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 30-07-2008, 11:20 AM
louie's Avatar
Senior Member
 
Join Date: Jan 2006
Location: Dublin, Ireland
Posts: 2,048
Nominated 5 Times in 3 Posts
Nominated TOTW/F/M Award(s): 1
louie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enough
Send a message via Yahoo to louie Send a message via Skype™ to louie
Default

where is this element on your form?

pubnum
__________________
:. Web Design & Development Web Design Ireland
:. Search Engines Optimization Search Engines Optimization
:. Directory Submission Directory Submission
:. News & Press Release Ireland GiveItSocks.com
:. Used Cars Ireland, Car Parts & Car Audio Cars For Sale, Car Parts & Accessories
:. I Have 2 Find It Directory SEF Directory
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 30-07-2008, 11:51 AM
garycocs's Avatar
Wannabe Geek
Recent Blog: Bangkok
 
Join Date: Oct 2007
Location: Dubland
Posts: 154
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
garycocs will become famous soon enough
Send a message via AIM to garycocs Send a message via MSN to garycocs Send a message via Yahoo to garycocs Send a message via Skype™ to garycocs
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4 (permalink)  
Old 30-07-2008, 12:04 PM
louie's Avatar
Senior Member
 
Join Date: Jan 2006
Location: Dublin, Ireland
Posts: 2,048
Nominated 5 Times in 3 Posts
Nominated TOTW/F/M Award(s): 1
louie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enough
Send a message via Yahoo to louie Send a message via Skype™ to louie
Default

I need more info and code...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5 (permalink)  
Old 30-07-2008, 12:07 PM
garycocs's Avatar
Wannabe Geek
Recent Blog: Bangkok
 
Join Date: Oct 2007
Location: Dubland
Posts: 154
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
garycocs will become famous soon enough
Send a message via AIM to garycocs Send a message via MSN to garycocs Send a message via Yahoo to garycocs Send a message via Skype™ to garycocs
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6 (permalink)  
Old 30-07-2008, 12:23 PM
garycocs's Avatar
Wannabe Geek
Recent Blog: Bangkok
 
Join Date: Oct 2007
Location: Dubland
Posts: 154
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
garycocs will become famous soon enough
Send a message via AIM to garycocs Send a message via MSN to garycocs Send a message via Yahoo to garycocs Send a message via Skype™ to garycocs
Default

Got it sorted Louie. Nice one!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7 (permalink)  
Old 30-07-2008, 12:23 PM
louie's Avatar
Senior Member
 
Join Date: Jan 2006
Location: Dublin, Ireland
Posts: 2,048
Nominated 5 Times in 3 Posts
Nominated TOTW/F/M Award(s): 1
louie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enough
Send a message via Yahoo to louie Send a message via Skype™ to louie
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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8 (permalink)  
Old 30-07-2008, 12:24 PM
garycocs's Avatar
Wannabe Geek
Recent Blog: Bangkok
 
Join Date: Oct 2007
Location: Dubland
Posts: 154
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
garycocs will become famous soon enough
Send a message via AIM to garycocs Send a message via MSN to garycocs Send a message via Yahoo to garycocs Send a message via Skype™ to garycocs
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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9 (permalink)  
Old 30-07-2008, 12:36 PM
louie's Avatar
Senior Member
 
Join Date: Jan 2006
Location: Dublin, Ireland
Posts: 2,048
Nominated 5 Times in 3 Posts
Nominated TOTW/F/M Award(s): 1
louie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enough
Send a message via Yahoo to louie Send a message via Skype™ to louie
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"> 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10 (permalink)  
Old 30-07-2008, 12:39 PM
louie's Avatar
Senior Member
 
Join Date: Jan 2006
Location: Dublin, Ireland
Posts: 2,048
Nominated 5 Times in 3 Posts
Nominated TOTW/F/M Award(s): 1
louie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enough
Send a message via Yahoo to louie Send a message via Skype™ to louie
Default

You got it.. cool
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
javascript

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads

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


Sponsored links

Paid On Results


All times are GMT +1. The time now is 01:41 PM.


Powered by: vBulletin Version 3.7.3, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
Hosted in Ireland by Blacknight - Test your ISP |Irish Hosting Directory| Armchair.ie|Logo by Eden Web Design|Avatars by Afterglow |