0

I have this html code:

<input type="text" id="text1" placeholder="نام کاربری">


and this submit button:

    <button type="submit" id="login-button" Onclick="window.location.href='Handler1.ashx?username='"+text1+"'" >ورود</button>


but up href not send html text box value with query string and send empty value,what happen?how can i solve that?thanks.

1 Answer 1

3

You need to call a function to set the url, rather than just reference the text box by id:

<script type="text/javascript">
function setUrl() {
    window.location.href = 'Handler1.ashx?username=' + document.getElementById('text1').value;
};
</script>
<button type="submit" id="login-button" Onclick="setUrl(); return false;" >

Note: The return false is to prevent the button from submitting the form. A better solution would be to remove the ;return false; and change the button type from submit to button.

Sign up to request clarification or add additional context in comments.

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.