homepage Welcome to WebmasterWorld Guest from 23.20.220.79
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Assign input variable to onclick event
AnonyMouse




msg:3685882
 10:20 am on Jun 28, 2008 (gmt 0)

Hi,

I have a search box that has a single input field and a submit button. When the submit button is pressed, an onClick event calls Google's urchinTracker.

I'd like to append whatever variable is put in the search box, to the onClick event so I can see it in Google Analytics:

<input name="searchterm" type="text">
<input type="submit" name="Submit" value="Submit" onClick=\"javascript:urchinTracker ('/siteSearch_SEARCHTERM_GOES_HERE'); >

Is this possible using JavaScript? Thanks in advance for any replies.

 

rocknbil




msg:3686018
 4:48 pm on Jun 28, 2008 (gmt 0)

I'd like to append whatever variable is put in the search box, to the onClick event so I can see it in Google Analytics:

Can't you just put the tracker on the search results page? I don't know that you can do this with the urchin, you might get some assistance from the analytics help files.

AnonyMouse




msg:3686060
 6:30 pm on Jun 28, 2008 (gmt 0)

Thanks for the reply - unfortunately I can't put the tracker on the results page, I have to catch the variable straight from the search form :-(

daveVk




msg:3686183
 1:14 am on Jun 29, 2008 (gmt 0)

Maybe

<input name="searchterm" id="searchBox" type="text">
<input type="submit" name="Submit" value="Submit" onClick="urchinTracker ('/siteSearch_' + document.getElementById( 'searchBox' ).value );" >

AnonyMouse




msg:3686436
 5:58 pm on Jun 29, 2008 (gmt 0)

Certainly looks about right - I've added it to the form code, now have to wait until it shows up in the Analytics report. Many thanks!

AnonyMouse




msg:3686821
 12:42 pm on Jun 30, 2008 (gmt 0)

Just to confirm that that did the trick, many thanks!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved