Welcome to WebmasterWorld Guest from 54.163.49.19

Forum Moderators: open

Message Too Old, No Replies

Assign input variable to onclick event

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

Junior Member

10+ Year Member

joined:May 13, 2003
posts: 151
votes: 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.

4:48 pm on June 28, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
posts:7999
votes: 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.

6:30 pm on June 28, 2008 (gmt 0)

Junior Member

10+ Year Member

joined:May 13, 2003
posts: 151
votes: 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 :-(
1:14 am on June 29, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 3, 2005
posts:1585
votes: 0


Maybe

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

5:58 pm on June 29, 2008 (gmt 0)

Junior Member

10+ Year Member

joined:May 13, 2003
posts: 151
votes: 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!
12:42 pm on June 30, 2008 (gmt 0)

Junior Member

10+ Year Member

joined:May 13, 2003
posts:151
votes: 0


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