• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

No space between form values?

I'm trying to write up a script that passes hidden values, but it's adding a space between the values. Here are the lines in question:

'<input class="" type="hidden" name="q" value="inurl:messageview.aspx?catid=" />\n' +
'<input class="ftforminputsmall" type="text" name="q" value="38" size="10" />'

The result would be inurl:messageview.aspx?catid= 38 rather than inurl:messageview.aspx?catid=38. Is there any way to avoid this?
 
(function() {
var searchForm = document.createElement('form');
searchForm.setAttribute('action', 'http://www.google.com/search?q=');
searchForm.setAttribute('method', 'get');
searchForm.setAttribute('autocomplete', 'on');
searchForm.setAttribute('style', 'position: absolute; top: 26.2%; left: 31.8%;');
searchForm.innerHTML = (
'<input class="ftforminputsmall" type="text" name="q" value="" size="18" />\n' +
'<input class="" type="hidden" name="q" value="site:forums.anandtech.com" />\n' +
'<input class="" type="hidden" name="q" value="inurl:messageview.aspx?catid=" />' +
'<input class="ftforminputsmall" type="text" name="q" value="catid" size="3" />\n' +
'<input class="ftformbutton" type="submit" value="Search" />'
);
 
I see. As all fields are same name there is a space between each field as they are concatenated. The only workaround I can think of is to either redirect using Javascript on button click, or to have one hidden field in place of the inurl and cat id, and using an onsubmit function to change the hidden field before posting.
 
Ok, quick example, I changed the following in the innerHTML of your script. Notice that I gave the fields unique ID's. the ***** = on click without the space as forum blocks it

'<input class="ftforminputsmall" type="text" name="searchphrase" id="searchphrase" value="" size="18" />\n' +
'<input class="ftforminputsmall" type="text" name="catid" id="catid" value="" size="18" />\n' +
'<input class="ftformbutton" type="button" value="Search" ******="Javascript:Redirect();" />');

Then I added this javascript function to the page, which builds a url using the form elements and goes to it. 🙂

function Redirect(){

var e1 = document.getElementById('searchphrase');
var e2 = document.getElementById('catid');

document.location = "http://www.google.com/search?q=" + e1.value +
" site:forums.anandtech.com" +
" inurl:messageview.aspx?catid=" + e2.value;

}
 
Hmm...am I doing something obviously wrong? I hit Search and nothing happens. I know I must be putting your function in the wrong place. :laugh:

Text

Thanks for the help!
 
Originally posted by: LoKe
Hmm...am I doing something obviously wrong? I hit Search and nothing happens. I know I must be putting your function in the wrong place. :laugh:

Text

Thanks for the help!

The button in your code has no event, the

src="Javascript:Redirect();

Should be (without the _ )

on_click="Javascript:Redirect();


 
Back
Top