Multiple form submits in body tag - submit

Although I have found a few questions related to this, none has quite addressed my specific situation. I have a PHP script that I want to call other scripts, without clicking. I have used this structure with success:
<body onload="form1.submit()">
<?php
.
.
.
if ($value=="yes"){
print<<<HERE
<form method="post" id="form1" action="nextapp.php">
<input="hidden" name="data" value="some data">
</form>
HERE
}
else
.
.
.
The above works perfectly. However, what if I want to be able to react to two different forms? This does NOT work:
<body onload="form1.submit(); form2.submit()">
nor does
<body onload="form1.submit()" onload="form2.submit()">
There were a few other weirder variations I tried that, not surprisingly (due to being so weird), didn't work.
Any ideas would be greatly appreciated!

Related

Textarea New Line on Enter Key not working on .NET Core MVC Application

I have a (probably) simple issue that I can't solve and need your help to resolve.
I created a new MVC application with Visual Studio 2017. I then created the necessary Model, View, and Controller to add some data to a SQL Server database.
However, in the TEXTAREA input, I am not able to use the Enter Key to go to a new line, like I am able to do here when I submitted this question. The Enter key does nothing.
I tried to trace the issue and was able to use this script to confirm that the Enter key was detected; however, still can't get a new line when I pressed the Enter key.
<script>
$(window).keydown(function (event) {
if ((event.which == 13) && ($(event.target)[0] == $("textarea")[0])) {
alert("One");
// event.preventDefault();
// return false;
}
});
</script>
Second, I added an onclick event to the textarea itself and still did not get a new line when clicked. There must be an override for the textarea in code that I am not able to find, which is probably part of the default app build in .NET VS2017.
<textarea rows="6" cols="20" class="form-control" asp-for="Notes" style="width: 96% !important;" onclick="this.value='Hello \n How R U?'"></textarea>
Is there any way to correct this issue and gain access to the full TEXTAREA functionalities and be able to provide a full text-based area for users to provide detailed comments in multiple lines?
Thank you for your reply.
I wrote following HTML code to face your problem but there was no problem!
<html>
<head>
<title>
test
</title>
</head>
<body>
<textarea rows="6" cols="20" class="form-control" asp-for="Notes" style="width: 96% !important;"
onclick="this.value='Hello \n How R U?'"></textarea>
</body>
</html>
Did you check your application by another browser?
If the problem still remains, In your browser inspect HTML code of your textarea and compare it to the tag helper equivalent of the textarea in your view code. This may help you to figure something out.

Microsoft edge v 17.17134 displays a # on postback

I recently stumbled upon a weird problem with the last version of Microsoft Edge (17.17134).
I have a really simple classic asp form that posts data to another asp form. If I post a string which contains
input
and
onclick=""
the receiving page will only display a "#" even if the code behind seems ok(see screenshot)
here's a snippet:
<!doctype html>
<html>
<body>
<form method="POST" action="to.asp">
<input type="text" name="hidInnerHTML" id="hidInnerHTML" style="width:500px;" value="steve would like your input on what to do when you activate the onclick= method" />
<br />
<input type="submit" value="click me"/>
</form>
</body>
</html>
and here is the code at the receiving end:
<!doctype html>
<html>
<body>
<div style="border:1px solid red;"></div>
</body>
</html>
It seems that certain keyword in the post data will trigger this effect. IE, chrome, probably Firefox, previous version of edge - all work correctly.
Any clues or idea what is happening here?
I'll take all the help I can get! :)
After doing a bit more research, i can see that this exact issue has just been raised here...
https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/19045578/
Check out the link for a fuller explanation but the short story is that you either set a "X-XSS-Protection" response header on your site with a value of "0" or you wait for the Windows 10 Insider Preview version (Build 17758) of Edge which includes the fix for this bug.
Microsoft Edge 44.17758.1.0
Microsoft EdgeHTML 18.17758

Get Textarea Value with Simpe HTML Dom

i using simple_html_dom.php
how to get textarea value if the website has used bad tag.
the textarea tag already closed before </textarea> like input tag.
Textarea HTML like below:
<textarea name="xxx" id="xxx" />this is value</textarea>
When i use this function, i dont get anything
$textarea = $html->find("textarea[name=xxx]");
$contents = $textarea->innertext;
echo $contents;
how to get 'this is value' using simple_html_dom.php or other alternative?
Thank you
Well, my previous comment won't work in this case, I'll leave it for info though...
Another approach is to clean it up before parsing it with simple_html_dom using Tidy extension. But it seems not to be working here either...
A last approach I can think of, and if this is your only problematic case, is to use regex to get what you want:
Using <textarea.*?name="xxx".*?id="xxx".*?\/>([^<]+)<\/textarea> ==> RegEx DEMO
The output will be in group one of the resulting array $match. Check this working code:
$input = <<<_DATA_
<textarea name="xxx" id="xxx" />this is value</textarea>
_DATA_;
$pattern = '/<textarea.*?name="xxx".*?id="xxx".*?\/>([^<]+)<\/textarea>/';
preg_match($pattern, $input, $match);
var_dump($match)
Working DEMO
It is easy to get the value of a Teaxtarea in javascript:
<script type=text/javascript>
function getValueTextarea()
{
var vl=document.getElementById("tx").value;
alert(vl);
}
</script>
<body>
<textarea id="tx">Value Of Textarea</textarea>
<input id="button" value="Get Value" onclick="getValueTextarea()">
</body>

Dart: How to close browser window?

How can I close a browser page via eg. an HTML button and Dart?
I've tried
window.close();
which doesn't appear to do anything;
I've also tried :
window.document.$dom_dispatchEvent();
using CloseEvent, but I'm not sure how to set that up.
I've also tried HTML and javascript without success.
Please advise how this can be done. It's needed for desktop-type apps IMO.
I used this:
<form method="post">
<input type="button" value="Close Window"
onclick="window.close()">
</form>
Maybe try
window.focus(); window.close()

jQuery UI Autocomplete can't figure it out

I decided to use jQuery UI for my autocomplete opposed to a plugin because I read that the plugins are deprecated. My overall goal is to have an autocomplete search bar that hits my database and returns users suggestions of city/state or zipcodes in a fashion similar to google. As of now I am not even sure that the .autocomplete function is being called. I scratched everything I had and decided to start with the basics. I downloaded the most recent version of jQuery UI from http://jqueryui.com/download and am trying to get the example that they use here http://jqueryui.com/demos/autocomplete/ to work. All the scripts that I have included seem to be connected at least linked through Dreamworks so I am fairly certain that the paths I have included are correct. The CSS and Javascripts that I have included are unaltered straight from the download. Below is my HTML code and my backend PHP code that is returning JSon formated data. Please help me. Maybe I need to include a function that deals with the JSon returned data but I am trying to follow the example although I see that they used a local array.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQueryUI Demo</title>
<link rel="stylesheet" href="css/ui-lightness/jquery-ui-1.8.17.custom.css" type="text/css" />
<script type="text/javascript" src ="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src ="js/jquery-ui-1.8.17.custom.min.js"></script>
</script>
<script type="text/javascript">
$(document).ready(function() {
$("#tags").autocomplete({
source: "search_me.php"
});
});
</script>
</head>
<body>
<div class="demo">
<div class="ui-widget">
<label for="tags">Tags: </label>
<input id="tags" />
</div>
</div><!-- End demo -->
<div class="demo-description">
<p>The Autocomplete widgets provides suggestions while you type into the field. Here the suggestions are tags for programming languages, give "ja" (for Java or JavaScript) a try.</p>
<p>The datasource is a simple JavaScript array, provided to the widget using the source-option.</p>
</div><!-- End demo-description -->
</body>
</html>
Below the PHP part.
<?php
include 'fh.inc.db.php';
$db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD) or
die ('Unable to connect. Check your connection parameters.');
mysql_select_db(MYSQL_DB, $db) or die(mysql_error($db));
$location = htmlspecialchars(trim($_GET['term'])); //gets the location of the search
$return_arr = array();
if(is_numeric($location)) {
$query = "SELECT
zipcode_id
FROM
user_zipcode
WHERE
zipcode_id REGEXP '^$location'
ORDER BY zipcode_id DESC LIMIT 10";
$result = mysql_query($query, $db) or die(mysql_error($db));
while($row = mysql_fetch_assoc($result)) {
extract($row);
$row_array['zipcode_id'] = $zipcode_id;
array_push($return_arr, $row_array);
}
}
mysql_close($db);
echo json_encode($return_arr);
?>
Thanks for the ideas. Here is an update.
I checked the xhr using firebug and made sure that it is responding thanks for that tip. also the above php code I hadn't initialized $return_arr so i took care of that. Also thanks for the clarification of the js required or rather not required. Now when I type in a zipcode a little box about a centimeter shows up underneath it but I can't see if anything is in there, I would guess not. I went to my php page and set it up to manually set the variable to "9408" and loaded the php page directly through my browser to see what it returned. This is what it returned.
[{"zipcode_id":"94089"},{"zipcode_id":"94088"},{"zipcode_id":"94087"},{"zipcode_id":"94086"},{"zipcode_id":"94085"},{"zipcode_id":"94083"},{"zipcode_id":"94080"}]
I then went to a JSON code validator at this url http://jsonformatter.curiousconcept.com/ at it informed me that my code is in fact returning JSON formatted data. Anymore suggestions to help me troubleshoot the problem would be terrific.
Wow after more research I stumbled across the answer on someone another post.
jquery autocomplete not working with JSON data
Pretty much the JSON returned data must contain Label or Value or both. Switched the zipcode_id to value in my $row_array and... boom goes the dynamite!
Your scripts (js files) references are not correct, should only be:
<!-- the jquery library -->
<script type="text/javascript" src ="js/jquery-1.7.1.min.js"></script>
<!-- the full compressed and minified jquery UI library -->
<script type="text/javascript" src ="js/jquery-ui-1.8.17.custom.min.js"></script>
The files "jquery.ui.core.js", "jquery.ui.widget.js" and "jquery.ui.position.js" are the separated development files, the jquery ui library is splitted into modules.
The file "jquery-ui-1.8.17.custom.min.js" contains them all, compressed and minified !
Concerning the data source, as stated in the "Overview" section of the Autocomplete documentation: when using a an URL, it must return json data, either of the form of:
an simple array of strings: ['string1', 'string2', ...]
or an array of objects with label (and a value - optionnal) property [{ label: "My Value 1", Value: "AA" }, ...]
I'm really not familiar with PHP so just make sure your php script returns one of those :-)

Resources