2

i have created one button in my javascript code, after clicking on this button it should go to the product.html

var outputb2 = "<p align=right>"+ "<input type=button value=productandservices onClick=window.location=product.html>" + "</input>" +"</p>";
    $('#product').append(outputb2);

where product is the div id in the product.html.but when i click on this button product and services..its not going to this product.html.how can i do..?

3
  • 5
    Use quotes properly "<input type='button' value='productandservices' onClick='window.location=product.html'>", However your code works jsfiddle.net/4F8RY Commented Apr 23, 2014 at 9:04
  • i tried everyone suggestion but still its not working..its not going to product.html.. Commented Apr 23, 2014 at 9:20
  • Are you getting any error in browser console? Commented Apr 23, 2014 at 9:27

7 Answers 7

4

I don't know why you are using javascript for this, unless you are sending some data with the click event. there is a simple html code to do what you want.

<a href="product.html#product">product and services</a>

If you must use java-script try this

onclick="javascript:location.href='product.html#product'" 
Sign up to request clarification or add additional context in comments.

Comments

4

Check this out

<script>
var outputb2 = "<p align=right>"+ "<input type=button id='productandservices' value=productandservices >" + "</input>" +"</p>";//added id
    $('#product').append(outputb2);

    $(document).ready(function()
    {

        $(document).on("click","#productandservices",function()
        {
            alert('clcik');
            window.location='product.html';
        });

    });

</script>

or

Enclose filename in quotes '

<script>
var outputb2 = "<p align=right>"+ "<input type=button id='productandservices' value=productandservices onClick=window.location='product.html' >" + "</input>" +"</p>";
    $('#product').append(outputb2);


</script>

Comments

3

Probably you need some escape characters in your code, it will work

var outputb2 = "<p 'align=right'>"+ "<input type='button' value='productandservices' onClick='window.location=\"product.html?someParam=hi\"'>" + "</input>" +"</p>";
$('#product').append(outputb2);

4 Comments

thanks its working ...but one thing tell me i want to pass one parameter to product .html..how can i..?
updated code added parameter to the url ?someParam=hi
hi..actually in my first page..i m searching some list.after clicking on the list item ..i m going to the respective list items profile page.this list item name is stored in text varable.now in the profile page i m going to this product.html means it should give information of product of that merchant only .so what i have to pass it to the url..window.location=product.html?...
if you have var someVariable = "hi";, you can code as var outputb2 = "<p 'align=right'>"+ "<input type='button' value='productandservices' onClick='window.location=\"product.html?parameterName="+someVariable+"\"'>" + "</input>" +"</p>"; hopefully you need to think and try on your own
3
var outputb2 = "<p align=right>";
outputb2 +=  "<input type='button' value='productandservices' onClick='window.location=product.html'>"
outputb2 += "</p>";

$('#product').append(outputb2);

1 Comment

Please provide an explanation.
2
var outputb2 = "<p align='right'><input type='button' value='productandservices' onClick='window.location=product.html'></input></p>";
$('#product').append(outputb2);

1 Comment

Please provide explanation.
2

right syntax to use:

<input TYPE="button" value=productandservices onclick="window.location.href='http://www.wherever.com'"> 

Another option is to create a link in the button:

<button type="button"><a href="yourlink.com">Link link</a></button>

Then use CSS to style the link and button, so that the link takes up the entire space within the button (so there's no miss-clicking by the user):

button, button a{position:relative;}
button a{top:0;left:0;bottom:0;right:0;}

but the point of a link is to go to another page. So trying to make a button act like a link is the wrong solution. My suggestion is that you should use a link and style it to look like a button.

<a href="/page2>Continue</a>

Comments

2

Try this :

var outputb2 = "<p align='right'>"+ 
                 "<input type='button' value='productandservices 'onClick='window.location=\"product.html\"' />" + 
               "</p>";
$('#product').append(outputb2);

Add ' like this : onClick='window.location=\"product.html\"'

Live demo

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.