Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
New Developer
rickysiu
Posts: 10
Registered: ‎09-19-2008
My Device: Not Specified

Cannot change href dynamically using javascript

Dear All,

 

  I try to change the href dynamically using javascript as following. (I try it in Firefox. It runs properly.)

 

    <SCRIPT language="JavaScript">
       function changeLink(link, str1, id)
       {
           document.getElementById(link).href=str1.toString() + document.getElementById(id).value;
       }

    </SCRIPT>

 

    <a href="#" onclick="changeLink('abc', 'http://www.google.com/search?q=', 'key');" id="abc">Search</a><br />

    <input type="text" id="key" value="love">

 

  However, when I click it, there is nothing happen. (I expected that it can go to the page immediately.)

 

Thanks.

Best Regards,

Ricky Siu

Please use plain text.
BlackBerry Development Advisor
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Cannot change href dynamically using javascript

Hi Ricky,

 

What version of the BlackBerry operating system are you running? 

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
New Developer
rickysiu
Posts: 10
Registered: ‎09-19-2008
My Device: Not Specified

Re: Cannot change href dynamically using javascript

Dear Tim,

 

  I am using JDE 4.7. However, I forgot to say that the html page is rendered in Browser Field instead of the BlackBerry Internet Browser.

 

Thanks.

Best Regards,

Ricky Siu

Please use plain text.
BlackBerry Development Advisor
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Cannot change href dynamically using javascript

Ah.. that's your problem right there.

 

4.7 BrowserField still uses the old 4.5 browser rendering and JavaScript engine.  So it doesn't really support DHTML and/or many JavaScript capabilities.

 

For the full lowdown on BrowserField I have referenced another thread where I explain the differences.

http://supportforums.blackberry.com/rim/board/message?board.id=browser_dev&thread.id=2140

 

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
New Developer
rickysiu
Posts: 10
Registered: ‎09-19-2008
My Device: Not Specified

Re: Cannot change href dynamically using javascript

Thanks, Tim.

 

Is there any way to change the href attribute according to the input text field using Browser Field?

Please use plain text.
BlackBerry Development Advisor
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Cannot change href dynamically using javascript

Well.... with BrowserField you must fetch all the resources yourself via Java code for the URL selected in BrowserField.  So you could do some logic in your Java code to detect that your user was on a certain page and then re-route the URL to the one you desire.  This could get tricky based on how complex your logic is on your web page that wants to change the URL.

 

But I can't think of any way off the top of my head of doing it in JavaScript within the HTML content. 

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
New Developer
rickysiu
Posts: 10
Registered: ‎09-19-2008
My Device: Not Specified

Re: Cannot change href dynamically using javascript

I use the Browser Field to read local HTML file. Thus, I cannot use the server code to dynamically generate the page. In fact, the link should be change according to the input text.

 

Thanks.

Please use plain text.