tiko

unread,
May 2, 2019, 11:16:27 AM5/2/19
to MIT App Inventor Forum
hello...
i have problam to execute javascript in my application appinventor!
i inserted web page in webviewer  (it contains a simple javascript code: an alert message after a button click)...
the web page displayed correctly but no thing a bout javascript !!!!
thank you.

TimAI2

unread,
May 2, 2019, 12:06:58 PM5/2/19
to MIT App Inventor Forum
Working here on Companion, see attached aia.
If compiling to apk change development to false
javascriptclick.aia

laroum toufik

unread,
May 2, 2019, 2:02:33 PM5/2/19
to MIT App Inventor Forum
waaw! that's work!!! so what was the problem!!!
- can you add a <select> tag, and whene we click on the button we show the selected item in an alert message.
- can you send me the html web page ? i want to see the html/javascript source code.

ABG

unread,
May 2, 2019, 2:15:08 PM5/2/19
to MIT App Inventor Forum
There's a collection of JavaScript Stunts at FAQ page
ABG

tiko

unread,
May 2, 2019, 2:25:49 PM5/2/19
to MIT App Inventor Forum
thank you,
but can you please send me some thing with a <select> tag
how to show the selected item with javascript in appinventor
please.

TimAI2

unread,
May 2, 2019, 3:14:21 PM5/2/19
to MIT App Inventor Forum
<!DOCTYPE html>
<html>
<body>

<select>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="opel">Opel</option>
  <option value="audi">Audi</option>
</select>
  
</body>
</html>


If you then want to return the selected item to the app you will need to use the webviewstring

TimAI2

unread,
May 2, 2019, 3:49:31 PM5/2/19
to mitappinv...@googlegroups.com
and to answer your question (how to show select in alert)

<!DOCTYPE html>
<html>
<body>

<select id = "choose">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="opel">Opel</option>
  <option value="audi">Audi</option>
</select>
  
  
  <button onclick="myFunction()">Show it</button>

<script>
function myFunction() {
  alert("Selection: "+ document.getElementById("choose").value);
}
</script>
  
  
</body>
</html>

or better (?)

<!DOCTYPE html>
<html>
<body>

<select id = "choose" onchange="myFunction()">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="opel">Opel</option>
  <option value="audi">Audi</option>
</select>

<script>
function myFunction() {
  alert("Selection: "+ document.getElementById("choose").value.toUpperCase());
}
</script>
  
  
</body>
</html>


tiko

unread,
May 3, 2019, 5:31:46 AM5/3/19
to MIT App Inventor Forum
all right now, thank you verry mach! (^ _ ^)
Reply all
Reply to author
Forward
0 new messages