0

What I want to do is to get the value of value and open it in new window with a specific size using JavaScript.

HTML

<a id="LNK" href="##" value="edit2.aspx?ren=<%# Eval("GLR_ID") %>" onclick="clickLink()">RENAME</a>

JavaScript

<script type="text/javascript">
        function clickLink() {
           var myLink = //I need to get the value of `value`
           window.open(myLink,'Rename','height=150px','width=250px');
           return false;
        }
</script> 

Please correct my grammar, Thank You.

1
  • The <%# tags seem to indicate to me that this involves more than just HTML and Javascript. Off the top of my head, though, I don't actually know what serverside language that is... Commented Aug 30, 2013 at 3:25

5 Answers 5

2

http://jsfiddle.net/trevordixon/4HE97/

Pass a reference to the anchor to clickLink:

<a id="LNK" href="##" value="edit2.aspx?ren=<%# Eval("GLR_ID") %>" onclick="clickLink(this)">RENAME</a>

Use getAttribute to get the value:

    function clickLink(a) {
       var myLink = a.getAttribute('value');
       window.open(myLink,'Rename','height=150px','width=250px');
       return false;
    }
Sign up to request clarification or add additional context in comments.

Comments

2
document.getElementById("LNK").getAttribute("value");

Comments

1

You can get DOM value using getElementByID().value

document.getElementByID('LNK').value

OR

You can pass argument into your onClick function.

onclick="clickLink(this.value)"

and in function.

function clickLink(value) {
var myLink = value;

1 Comment

The window open but no content displayed.
1

Check out this solution:

function clickLink(e) {
  var myLink = e.getAttribute("value");
  window.open(myLink,'Rename','height=150px','width=250px');
  return false;
}

HTML:<a id="LNK" href="##" value="edit2" onclick="clickLink(this)">RENAME</a>

A working example can be found here

Comments

1

Try this

 window.clickLink = function(a) {
           var myLink = a.getAttribute('value');
           window.open(myLink,'Rename','height=150px','width=250px');
           return false;
        }

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.