0

I'm having some issues with my javascript link

I have a hidden input fields with the name "domein"

I'm having the following div with a onclick script

<div id="button" onclick="window.open('http://www.mylink.nl/?domein=' + document.getElementById('domein').value ,'_blank') ">
<strong>button text</strong>
</div>

The link does not open in a new tab neither does it shows the values from the 'domein' value from the hidden field in the url.

Can you guys please help me out?

My second question: How can I let the url be only http://www.mylink.nl when 'domein' value = empty.

2

1 Answer 1

1

This works:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<input type="hidden" id="test" value="test">
<div id="button" onclick="window.open('http://www.example.com/?domein=' + document.getElementById('test').value,'_blank');">
<strong>button text</strong>
</div>
</body>
</html>

New tab url:

http://www.example.com/?domein=test

Please check and make sure you have your hidden input defined with id domein...

******************************UPDATE********************************

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<script type="text/javascript">
function submit()
{
    if(!document.getElementById("test").value.match(/\S/))
    {
        window.open('http://www.example.com/','_blank');
    }
    else
    {
        window.open('http://www.example.com/?domein=' + document.getElementById('test').value,'_blank');
    }
}
</script>
<input type="hidden" id="test" value="test">
<div id="button" onclick="submit()">
<strong>button text</strong>
</div>
</body>
</html>
Sign up to request clarification or add additional context in comments.

3 Comments

My second question: How can I let the url be only mylink.nl when 'domein' value = empty.
Thank you, I didn't had a hidden field on that particular page indeed.. do you mind answering my second question? :)
My second question: How can I let the url be only mylink.nl when 'domein' value = empty. –

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.