0

I have a program that generates a web page that contains a button. I want to be able to append the URL for that button. tblSubscriptionlist.asp to tblSubscriptionlist.asp?Type=3 The generated element looks like this:

<a class="ewGridInsert" title="" data-caption="Insert" href="" onclick="return ewForms(this).Submit('tblSubscriptionlist.asp');" style="margin-right: 10px;" data-original-title="Insert"><span data-phrase="GridInsertLink" class="glyphicon ewIcon" data-caption="Insert" style="font-weight: 800;">Submit</span></a>

I tried:

$('.ewGridInsert').attr("href",onclick="return ewForms(this).Submit('tblSubscriptionlist.asp?type=3');");

but it added to the href not the actual URL.

Any assistance would be appreciated.

freedomn-m
  • 27,664
  • 8
  • 35
  • 57
ready4data
  • 65
  • 6
  • Try [here](https://stackoverflow.com/search?q=%5Bjavascript%5D+change+url) - the [first result](https://stackoverflow.com/questions/824349/how-do-i-modify-the-url-without-reloading-the-page) *seems* to be what you're after: `window.history.pushState` – freedomn-m Jan 20 '22 at 15:06
  • No, That modifies the current browser URL, I want to change the URL in the onClick section of the button. – ready4data Jan 20 '22 at 16:55
  • Thanks for clarifying - looks like you want: `.attr("onclick", "return ewForms(this).Submit...` – freedomn-m Jan 20 '22 at 17:12
  • 1
    Thanks feedomn. That worked: ```$('.ewGridInsert').attr("onclick", "return ewForms(this).Submit('tblSubscriptionlist.asp?type=3');")``` – ready4data Jan 20 '22 at 17:31

1 Answers1

0

This is a loaded situation because the <a/> tag link is not being used as a normal hyperlink, but overridden as a form submission link.

You need to decide whether you want the link to submit a form, or navigate to somewhere else using the 'href' attribute. Doing both is not really viable.

It appears to be committing to the 'onclick' attribute, and abandoning the 'href' attribute. So, your solution needs to be focused around what the 'onclick' attribute is accomplishing. If it is actually submitting the <form> it resides in, then perhaps you should add a hidden <input/> to this form with the 'name' "Type" and give it a 'value' of 3.

<input type="hidden" name="Type" value="3" />

When the <form> submits, assuming it's a GET type of HTTP request, the hidden input's name and value will get appended to the end of the GET request's URL, like you've described.

But, if I'm missing something, please clarify what else is going on and we can work it out further.

Also, does the parameter "Type" need to have a capitalized 'T'? (The original question has it capitalized while the edit to the question has it in lowercase.)