Jump to content

JS Google search box change attribute?

SlimeyStuff

So i'm currently making a simple website for a school projekt which includes having a simple javascript on it (which we don't have to code ourselves since we haven't learned js yet) 

So i want a google search box on the site but since it's not a real website (it will only be used locally) i can't add a domain name for the search so instead i'm trying to change the value of the attribute that sets the domain name so that it will add the current localhost name. This is what it currently looks like: 

<input type="hidden" name="sitesearch" value="#" id="change_url"/><script>    var meow = '"' + location.host + '"';    document.getElementById("change_url").setAttribute("value", meow);</script>

 

However it does work if i'm not using a variable, like this:

    document.getElementById("change_url").setAttribute("value", "turtle");

 

 

What am I doing wrong? Is it easier some other way?
Halp pls :(

Meow.

Link to comment
Share on other sites

Link to post
Share on other sites

Don't add extra quotes around your variable. You can just do this:

document.getElementById("change_url").setAttribute("value", location.host);

Quotes are only used to declare a string value as a variable, so something that is already a variable doesn't need it.

Link to comment
Share on other sites

Link to post
Share on other sites

Don't add extra quotes around your variable. You can just do this:

document.getElementById("change_url").setAttribute("value", location.host);

Quotes are only used to declare a string value as a variable, so something that is already a variable doesn't need it.

 

I've tried that, if i do that, it just does a normal google search....

 

4iCBYFY.png

Meow.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×